#version 140
uniform vec3 lpos;
in vec3 vnorm;
in vec4 MCVertex;
in vec4 TexCoord0;

out vec2 TexCoord;
out float lightIntensity;

uniform mat4 MVMatrix;
uniform mat4 MVPMatrix;
uniform mat3 NormalMatrix;

const float spec_coe=0.1;
const float diff_coe=0.4;
const float ambi_coe=1-spec_coe-diff_coe;

void main(){
    vec3 epos=vec3(MVMatrix * MCVertex);
    vec3 tnorm=normalize(NormalMatrix * vnorm);
    vec3 lightVec = normalize(lpos-epos);
    vec3 reflectVec= reflect(-lightVec,tnorm);
    vec3 viewVec = normalize(-epos);
    
    float spec=clamp(dot(reflectVec,viewVec),0.0,1.0);
    spec= pow(spec,16);
    lightIntensity = diff_coe * max(dot(lightVec,tnorm),0.0) + spec_coe*spec;
    
    TexCoord=TexCoord0.st;
    gl_Position = MVPMatrix * MCVertex;
}
